import Taro, { Component } from "@tarojs/taro-h5";
import { onError, Provider } from "@tarojs/mobx-h5";
import '@tarojs/async-await';

import counterStore from "./store/index";
import './app.scss';
// Mobx 异常监听抛出异常
import Nerv from 'nervjs';
import { View, Tabbar, TabbarContainer, TabbarPanel } from '@tarojs/components';
import { Router, createHistory, mountApis } from '@tarojs/router';
Taro.initPxTransform({
  "designWidth": 750,
  "deviceRatio": {
    "640": 1.17,
    "750": 1,
    "828": 0.905
  }
});

const _taroHistory = createHistory({
  mode: "hash",
  basename: "/",
  customRoutes: {},
  firstPagePath: "/pages/home/index"
});

mountApis({
  "basename": "/",
  "customRoutes": {}
}, _taroHistory);
onError(error => {
  throw error;
});
const store = {
  counterStore
};
const { setTabList } = counterStore;
class App extends Component {
  state = {
    __tabs: {
      backgroundColor: '#fff',
      selectedColor: '#13C2C2',
      borderStyle: 'white',
      list: [{
        iconPath: require("./assets/images/tabbar/home.png"),
        selectedIconPath: require("./assets/images/tabbar/home_active.png"),
        pagePath: "/pages/home/index",
        text: '首页'
      }, {
        iconPath: require("./assets/images/tabbar/user.png"),
        selectedIconPath: require("./assets/images/tabbar/user_active.png"),
        pagePath: "/pages/member/index",
        text: '会员中心'
      }],
      mode: "hash",
      basename: "/",
      customRoutes: {}
    }
  };

  constructor() {
    super(...arguments);
  }
  componentDidMount() {
    setTabList(this.config.tabBar);
  }
  // 请勿修改此函数
  render() {
    return <Provider store={store}>
          
        <TabbarContainer>
          
        <TabbarPanel>
          
                <Router mode={"hash"} history={_taroHistory} routes={[{
            path: '/pages/home/index',
            componentLoader: () => import( /* webpackChunkName: "home_index" */'./pages/home/index'),
            isIndex: true
          }, {
            path: '/pages/member/index',
            componentLoader: () => import( /* webpackChunkName: "member_index" */'./pages/member/index'),
            isIndex: false
          }, {
            path: '/pages/member/login',
            componentLoader: () => import( /* webpackChunkName: "member_login" */'./pages/member/login'),
            isIndex: false
          }, {
            path: '/pages/error/index',
            componentLoader: () => import( /* webpackChunkName: "error_index" */'./pages/error/index'),
            isIndex: false
          }]} customRoutes={{}} />
                
        </TabbarPanel>
        <Tabbar conf={this.state.__tabs} homePage="pages/home/index" />
        </TabbarContainer>
        </Provider>;
  }
  config = {
    pages: ["/pages/home/index", "/pages/member/index", "/pages/member/login", "/pages/error/index"],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: '演示店铺',
      navigationBarTextStyle: 'black',
      backgroundColor: '#f7f7f7',
      enablePullDownRefresh: true
    },
    tabBar: { backgroundColor: '#fff', selectedColor: '#13C2C2', borderStyle: 'white', list: [{ iconPath: require("./assets/images/tabbar/home.png"), selectedIconPath: require("./assets/images/tabbar/home_active.png"), pagePath: "/pages/home/index", text: '首页' }, { iconPath: require("./assets/images/tabbar/user.png"), selectedIconPath: require("./assets/images/tabbar/user_active.png"), pagePath: "/pages/member/index", text: '会员中心' }], mode: "hash",
      basename: "/",
      customRoutes: {}
    },
    permission: {
      'scope.userLocation': {
        desc: '你的位置信息将用于购物地址使用'
      }
    }
  };

  componentWillMount() {
    Taro.initTabBarApis(this, Taro);
  }

}
Nerv.render(<App />, document.getElementById('app'));